<?php
/**
* YouPin.php file
* create by ljanson
* @2013-3-4
*/
require_once 'function.php';
$data = isset($_POST["data"]) ? $_POST["data"] : "";

if($data){
	header("Content-Type: text/html; charset=utf-8");
	require_once 'DBFactory.php';
	$db = DBFactory::getInstance("YouPin");
	$ConverData = clean(json_decode($data, true));
	$sql = "";

	foreach($ConverData as $key => $val){
		$res = $db->isOne("`content`", "`id`", array("`goodsID`='{$val["id"]}'"));		
		$isdel = ($val["status"] == 2) ? 1 : 0;
		if($res){
			$sql .= "UPDATE `content` SET `publishDate`='{$val["published_date"]}',`picture`='{$val["picture_url"]}',`title`='{$val["title"]}',`goodsUrl`='{$val["url"]}',`desc`='{$val["description"]}',`originalPrice`={$val["list_price"]},`currentPrice`={$val["price"]},`shared`={$val["shared_count"]},`collected`={$val["collected_count"]},`updater`='{$val["editor"]}',`status`={$val["status"]},`sort`={$val["priority"]},`comefrom`={$val["is_external_picture"]},`cateID`={$val["category_id"]},`saledNum`={$val["purchaser_count"]},`commission`={$val["commission_percentage"]},`isDel`={$isdel},`saygood`={$val['liker_count']} WHERE `goodsID`='{$val["id"]}';";
		}
		else{
			$sql .= "INSERT INTO `content`(`publishDate`,`picture`,`title`,`goodsUrl`,`desc`,`originalPrice`,`currentPrice`,`shared`,`collected`,`updater`,`status`,`sort`,`comefrom`,`cateID`,`saledNum`,`commission`,`isDel`,`goodsID`,`saygood`) VALUES('{$val["published_date"]}', '{$val["picture_url"]}', '{$val["title"]}', '{$val["url"]}', '{$val["description"]}', {$val["list_price"]}, {$val["price"]}, {$val["shared_count"]}, {$val["collected_count"]}, '{$val["editor"]}', {$val["status"]}, {$val["priority"]}, {$val["is_external_picture"]}, {$val["category_id"]}, {$val["purchaser_count"]}, {$val["commission_percentage"]}, {$isdel}, '{$val["id"]}', {$val['liker_count']});";
		}
	}
	
	$res = $db->DoExecute($sql);
	$ret = $res ? 1 : 2;
	$msg = $res ? "执行成功" : "执行失败";
	echo json_encode(array("ret"=>$ret, "msg"=>$msg));
	exit;
}
else{
	echo json_encode(array("ret"=>0, "msg"=>"参数错误，类型错误或数据为空"));
	exit;
}
